# Makefile for compiling and simulating with iverilog

# Directories
SRC_DIR := ./src
BUILD_DIR := build

# Files
SRC_FILES := $(wildcard $(SRC_DIR)/*.*v)
TB_FILE := 
OUT_FILE := $(BUILD_DIR)/simulation.vvp

# Tools
IVERILOG := "D:/ProgramFiles/iverilog/bin/iverilog.exe"
VVP := "D:/ProgramFiles/iverilog/bin/vvp.exe"

# 根据操作系统定义不同的命令
ifeq ($(OS),Windows_NT)
  DEL_CMD = del
else
  DEL_CMD = rm
endif

# Targets
all: $(OUT_FILE) 
	$(VVP) -v -n $(OUT_FILE) -l $(BUILD_DIR)/build.log
	@echo "Simulation completed. Check build/build.log for details."

$(OUT_FILE): $(SRC_FILES) $(TB_FILE) | $(BUILD_DIR)
	$(IVERILOG) -D IVERILOG -g2005-sv -o $(OUT_FILE) $(TB_FILE) $(SRC_FILES)

$(BUILD_DIR):
	mkdir $(BUILD_DIR)

clean:
	$(DEL_CMD) $(BUILD_DIR)

.PHONY: all clean